from .celery import app

@app.task
def banner_update():
    from home import ser
    from home import models
    from django.conf import settings
    from django.core.cache import cache
    queryset_banner= models.Banner.objects.filter(is_delete=False, is_show=True).order_by('display_order')[:settings.BANNER_COUNTER]
    ser_banner = ser.BannerModelSerializer(instance=queryset_banner, many=True)
    print(ser_banner.data) #OrderedDict([('name', 'banner2'), ('link', 'actual-course'), ('img', '/media/banner/banner2.png')
    '''
    response.data获取到的img是有自动拼接ip地址的
    因为ser_banner.data获取到的img地址没有ip地址，所以需要我们手动拼接
    '''
    for banner in ser_banner.data:
        banner['img'] = 'http://127.0.0.1:8001'+banner['img']
    cache.set('banner_list', ser_banner.data)
    return True
